<?php 
define('CACHE_ROOT',substr(dirname(__FILE__),0,-9).'open/demo/caches'.DIRECTORY_SEPARATOR);

$data = [];
$plat = !empty($_POST['plat'])?$_POST['plat']:'an';
if($plat == 'ios'){
	$time = date("G:i:s",time());
	$log = "---------- $time ios start -----------\n";
	$log .= '$_POST = '.var_export($_POST, true).';';
	logCron('localhost_testInfo.',$log);
	$_POST['info'] = iosData($_POST['info']);
	$data['point_list'] = json_encode(@$_POST['info']);
}else{
	$data['point_list'] = @$_POST['info'];
}
$time = date("G:i:s",time());
$log = "---------- $time start -----------\n";
$log .= '$_POST = '.var_export($_POST, true).';';
logCron('localhost_testInfo.',$log);
unset($log);
$info  = add($data);
$log = "\n";
$log .= '$info = '.var_export($info, true).';';
$log .= "---------- $time end  -----------\n";
logCron('localhost_testInfo.',$log);
unset($log);
print_R($info);die;
function add($data = []){
	$url = 'http://yingyan.baidu.com/api/v3/track/addpoints';
	$curl = curl_init();
	$data['ak'] = 'PfIOOKtAPpf91ksRfecNyGzQsCa9h2jy';
    $data['service_id'] = '203049';
	curl_setopt ($curl, CURLOPT_URL, $url);  
    curl_setopt ($curl, CURLOPT_REFERER, "http://oa.fc62.com/");  
	curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
	curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
	curl_setopt($curl,CURLOPT_POST,true); // post传输数据
	curl_setopt($curl,CURLOPT_POSTFIELDS,$data);// post传输数据
	$output = curl_exec($curl);
	//var_dump( curl_error($curl) );//如果执行curl过程中出现异常，可打开此开关，以便查看异常内容
	curl_close($curl);
	return $output;
}
function logCron($filename,$log){
	$file = CACHE_ROOT.$filename. date('Ymd').'.log.php';
	if(!is_file($file)) $log = "<?php\n die();\n" . $log;
	$fp = fopen($file, "a");
	fwrite($fp, $log);
	fclose($fp);
}
function iosData($info = []){
	$data = [];
	$a = 0;
	$b = 0;
	foreach($info as $key=>$val){
		if($a%9 == 0) $b++;
		foreach($val as $k=>$v){
			$data[$b-1][$k] = $v;
		}
		
		$a++;
	}
	return $data;
}
?>